/**
 * @created 05/06/07
 * @bbrison 
 * This class is used in the braided multipath algorithm and does the same thing it does in the directed diffusion
 * algorithm.
 */




package communication.thirdLayer;

import communication.thirdLayer.*;
import communication.pack.*;
import kernel.*;

public class RAltWait extends Thread {

    /**
     * The time to wait before sending the reinforcement. It needs to be multiplied by the number of routers in the network.
     */
    private int TIME_TO_WAIT = 2000;

    
    private Simulator _s;
    private Reinforcement _p;
    private Reinforcement _alt;
    private double _count;

    public RAltWait(Simulator s, Reinforcement p, Reinforcement alt) {
	super();
	_p=p;
	_alt=alt;
	_s=s;
    }

    public Reinforcement getPrimaryPackage() {
	return _p;
    }

    public Reinforcement getAlternativePackage() {
	return _alt;
    }

    /**
     * The main method of the thread. It begins the count, and then, when the time is reached, sends the reinforcement, that begins the 
     * reinforcement procedure.
     */
    public void run() {
	_count = _s.getTime();
	while(_s.getTime() < _count + (_s.getCommunicationManager().getTLManager().getTLProtocol().getNetwork().size())*TIME_TO_WAIT);
	_p.getSenderId().getRouter().send(_p);
	//_alt.getSenderId().getRouter().send(_alt);
    }
}
